#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
开放商户 - 结算账户变更功能使用示例
"""

import os
import sys

# 添加项目根目录到Python路径，确保能够导入jlpay包
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))

from examples.base_example import BaseExample
from jlpay.services.openmerch.change.change_service import ChangeService
from jlpay.model.openmerch.change.settle_account_change import SettleAccountChangeRequest


class SettleAccountChangeExample(BaseExample):
    """结算账户变更示例类"""
    
    def __init__(self):
        """初始化示例类"""
        super().__init__("examples.openmerch.change.settle_account")
        self.change_service = ChangeService(self.config)
    
    def build_settle_account_change_request(self):
        """构建结算账户变更请求"""
        request = SettleAccountChangeRequest()
        
        # 构建辅助证明材料
        proof_info = [
            {
                "proof_type": "01",  # 证明类型：01-营业执照
                "proof_name": "营业执照",
                "proof_url": "https://example.com/license.jpg"
            },
            {
                "proof_type": "02",  # 证明类型：02-身份证
                "proof_name": "法人身份证",
                "proof_url": "https://example.com/idcard.jpg"
            }
        ]
        
        # 设置请求参数
        request.set_apply_id("b8659ea518d14c99b78b5ad000a0729c")  # 使用新的申请单号
        request.set_merch_no("849584358140109")  # 使用新的商户号
        request.set_settle_type("01")  # 结算类型：01-对私
        request.set_account_name("张三")
        request.set_account_no("6222021234567890123")
        request.set_bank_code("ICBC")  # 工商银行
        request.set_bank_branch_id("102100000000")
        request.set_bank_branch_name("工商银行北京朝阳支行")
        request.set_account_pic("https://example.com/account.jpg")
        request.set_bank_set_phone("13800138000")
        request.set_cert_type("01")  # 证件类型：01-身份证
        request.set_delegatee_id_card("110101199001011234")
        request.set_delegatee_cert_period_begin("2020-01-01")
        request.set_delegatee_cert_period_end("2030-01-01")
        request.set_acct_license("https://example.com/license.jpg")
        request.set_acct_cert_front_pic("https://example.com/idcard_front.jpg")
        request.set_acct_cert_back_pic("https://example.com/idcard_back.jpg")
        request.set_acct_auth_letter("https://example.com/auth_letter.jpg")
        request.set_identity_face_pic("https://example.com/face.jpg")
        request.set_acct_face_pic("https://example.com/acct_face.jpg")
        request.set_proof_info(proof_info)
        
        return request
    
    def demo(self):
        """执行结算账户变更示例"""
        self.logger.info("开始执行结算账户变更示例")
        
        # 构建请求
        request = self.build_settle_account_change_request()
        
        # 发送请求并处理响应
        self.send_request_and_handle_response(
            self.change_service.change_settle_account,
            "结算账户变更",
            request
        )
        
        self.logger.info("结算账户变更示例执行完毕")


if __name__ == "__main__":
    example = SettleAccountChangeExample()
    example.logger.info("=" * 50)
    example.logger.info("===== 结算账户变更示例 开始 =====")
    example.logger.info("=" * 50)
    
    example.demo()
    
    example.logger.info("=" * 50)
    example.logger.info("===== 结算账户变更示例执行完毕 =====")
    example.logger.info("=" * 50) 